import { Button } from "antd";
import React, { useEffect, useState } from "react";

const TestUseState: React.FC = () => {
  const [count, setCount] = useState<number>(0);

  function add() {
    setCount(count + 1);
    // setCount(prev => prev + 1);
    // setCount(count + 1);
    Promise.resolve().then(() => {
      setCount(count + 1);
    });
  }

  useEffect(() => {
    let first = false;
    if (!first) {
      setCount(count + 1);
    }

    return () => {
      first = true;
    };
  }, [count]);

  console.log("render");

  return (
    <>
      <h3>计数：{count}</h3>
      <Button onClick={add}>加</Button>
    </>
  );
};
export default TestUseState;
